<?php
class M_DbTable_Tour extends Apps_Db_Table_Abstract {
	protected $_name = 'tour';

	const STATUS_ACTIVE  	= 1;
	const STATUS_INACTIVE  	= 0;
	const STATUS_DELETED  	= -1;

	const SPECIAL_OFFER_TRUE 	= 1;
	const SPECIAL_OFFER_FALSE 	= 0;

	public function getList() {
		$q = $this->_db
				  ->select()
				  ->from(array('t'   => $this->_name), null)
				  ->join(array('t_c' => 'tour_category'), 't_c.id = t.tour_category_id', null)
				  ->join(array('t_s' => 'tour_style'), 't_s.id = t.tour_style_id', null)
				  ->join(array('c'	 => 'country'), 'c.id = t.country_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = t.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_TOUR)
				  ->where('t.status != ? ', self::STATUS_DELETED)
				  ->order('t.created_date DESC')
				  ->columns(
				  		array('id'					=> 't.id',
							  'title'				=> 'a.en_title',
				  		      'special_offer'       => 't.special_offer',
				  		      'status'              => 't.status',
							  'tour_category_id'	=> 't_c.id',
							  'tour_category_title'	=> 't_c.en_title',
							  'tour_style_id'    	=> 't_s.id',
							  'tour_style_title'	=> 't_s.en_title',
							  'country_id'			=> 'c.id',
							  'country'				=> 'c.en_name'
				  ));
        return $q;
	}

	//get 1 tour, article by tourId
	public function getTour($tourId) {
		$q = $this->_db
				  ->select()
				  ->from(array('t'   => $this->_name), null)
				  ->join(array('t_c' => 'tour_category'), 't_c.id = t.tour_category_id', null)
				  ->join(array('t_s' => 'tour_style'), 't_s.id = t.tour_style_id', null)
				  ->join(array('c'	 => 'country'), 'c.id = t.country_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = t.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_TOUR)
				  ->where('t.id =?', $tourId)
				  ->columns(
				  		array('id'					=>  't.id',
							  'price'				=>	't.price',
				  		      'special_offer'       =>  't.special_offer',
							  'en_price'			=>	't.en_price',
							  'itinerary'			=>	't.itinerary',
							  'en_itinerary'		=>	't.en_itinerary',
							  'note_price'			=>	't.note_price',
							  'en_note_price'		=>	't.en_note_price',
							  'description'			=>	't.description',
							  'meta_description'	=>	't.meta_description',
							  'meta_keyword'		=>	't.meta_keyword',
							  'header_title'		=>	't.header_title',

							  'title'				=>	'a.title',
							  'en_title'			=>	'a.en_title',
				  			  'overview'			=>	'a.overview',
				  			  'en_overview'			=>	'a.en_overview',
				  			  'detail'				=>	'a.detail',
				  			  'en_detail'			=>	'a.en_detail',

							  'tour_category_id'	=>	't_c.id',
							  'tour_style_id'		=>	't_s.id',
							  'country_id'			=>	'c.id'
				  ));
		return $q;
	}
}